#include <functional>
#include <iostream>
#include <numeric>
int func(int x, int y) { return x + 3 * y; }
struct sum_class {
  int operator()(int x, int y) { return x + 4 * y; };
} sum_obj;
int main() {
  int number[] = {1, 2, 3, 4, 5, 6, 7, 8};
  // 累加number里面的所有元素，初始值为0
  auto num_sum = std::accumulate(number, number + 7, 0);
  // 传递自定义的函数对象
  auto num_result = std::accumulate(number, number + 7, 0, func);
  // 传递functional对象
  auto num_minus = std::accumulate(number, number + 7, 0, std::minus<int>());
  // 对象调用
  auto num_sum_obj = std::accumulate(number, number + 7, 0, sum_obj);
  std::cout << num_sum << "\n";     // 28
  std::cout << num_result << "\n";  // 84
  std::cout << num_minus << "\n";   // -28
  std::cout << num_sum_obj << "\n"; // -112
}
